home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / documentation / tutorial / intl / datamgmt / demos-1.1 / Utility.java < prev   
Encoding:
Java Source  |  1997-07-13  |  5.5 KB  |  137 lines

  1. /*
  2.  * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for NON-COMMERCIAL purposes and without
  6.  * fee is hereby granted provided that this copyright notice
  7.  * appears in all copies. Please refer to the file "copyright.html"
  8.  * for further important copyright and licensing information.
  9.  *
  10.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  11.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  14.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  15.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  16.  */
  17. /*
  18.  * @(#)Utility.java    1.1 96/11/23
  19.  *
  20.  * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
  21.  * (C) Copyright IBM Corp. 1996 - All Rights Reserved
  22.  *
  23.  * Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
  24.  *
  25.  *   The original version of this source code and documentation is copyrighted
  26.  * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
  27.  * materials are provided under terms of a License Agreement between Taligent
  28.  * and Sun. This technology is protected by multiple US and International
  29.  * patents. This notice and attribution to Taligent may not be removed.
  30.  *   Taligent is a registered trademark of Taligent, Inc.
  31.  *
  32.  * Permission to use, copy, modify, and distribute this software
  33.  * and its documentation for NON-COMMERCIAL purposes and without
  34.  * fee is hereby granted provided that this copyright notice
  35.  * appears in all copies. Please refer to the file "copyright.html"
  36.  * for further important copyright and licensing information.
  37.  *
  38.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  39.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  40.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  41.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  42.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  43.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  44.  *
  45.  */
  46.  
  47. import java.awt.*;
  48. import java.lang.*;
  49. import java.util.*;
  50.  
  51. public class Utility
  52. {
  53.     public static final Font titleFont = new Font("TimesRoman",Font.BOLD,18);
  54.     public static final Font labelFont = new Font("TimesRoman",Font.BOLD,14);
  55.     public static final Font choiceFont = new Font("Helvetica",Font.BOLD,12);
  56.     public static final Font editFont = new Font("Helvetica",Font.PLAIN,14);
  57.     public static final Font creditFont = new Font("Helvetica",Font.PLAIN,10);
  58.  
  59.     public static final Color bgColor = Color.lightGray;
  60. //  public static final Color choiceColor = Color.white;
  61.     public static final Color choiceColor = Color.lightGray;
  62.  
  63.     public static final String copyright1 =
  64.         "(C) Copyright Taligent, Inc. 1996-1997 - All Rights Reserved";
  65.     public static final String copyright2 =
  66.         "Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.";
  67.  
  68.     /**
  69.     Provides easy way to use basic functions of GridBagLayout, without
  70.     the complications. After building a panel, and inserting all the
  71.     * subcomponents, call this to lay it out in the desired number of columns.
  72.     */
  73.     public static void fixGrid(Container cont, int columns) {
  74.         GridBagLayout gridbag = new GridBagLayout();
  75.         cont.setLayout(gridbag);
  76.  
  77.         GridBagConstraints c = new GridBagConstraints();
  78.         c.fill = GridBagConstraints.VERTICAL;
  79.         c.weightx = 1.0;
  80.         c.insets = new Insets(2,2,2,2);
  81.  
  82.         Component[] components = cont.getComponents();
  83.         for (int i = 0; i < components.length; ++i) {
  84.             int colNumber = i%columns;
  85.             c.gridwidth = 1;    // default
  86.             if ((i%columns) == columns - 1)
  87.                 c.gridwidth = GridBagConstraints.REMAINDER;    // last in grid
  88.             if (components[i] instanceof Label) {
  89.                 switch (((Label)components[i]).getAlignment()) {
  90.                 case Label.CENTER: c.anchor = GridBagConstraints.CENTER; break;
  91.                 case Label.LEFT: c.anchor = GridBagConstraints.WEST; break;
  92.                 case Label.RIGHT: c.anchor = GridBagConstraints.EAST; break;
  93.                 }
  94.             }
  95.             gridbag.setConstraints(components[i], c);
  96.         }
  97.  
  98.     }
  99.  
  100.     /**
  101.     Provides easy way to change the spacing around an object in a GridBagLayout.
  102.     Call AFTER fixGridBag, passing in the container, the component, and the
  103.     new insets.
  104.     */
  105.     public static void setInsets(Container cont, Component comp, Insets insets) {
  106.         GridBagLayout gbl = (GridBagLayout)cont.getLayout();
  107.         GridBagConstraints g = gbl.getConstraints(comp);
  108.         g.insets = insets;
  109.         gbl.setConstraints(comp,g);
  110.     }
  111.  
  112.  
  113.     // to avoid goofy updates and misplaced cursors
  114.     public static void setText(TextComponent area, String newText) {
  115.         String foo = area.getText();
  116.         if (foo.equals(newText)) return;
  117.         area.setText(newText);
  118.     }
  119.     /**
  120.      * Get the G7 locale list for demos.
  121.      */
  122.     public static Locale[] getG7Locales() {
  123.         return localeList;
  124.     }
  125.     private static Locale[] localeList = {
  126.         new Locale("DA", "DK", ""),
  127.         new Locale("EN", "US", ""),
  128.         new Locale("EN", "GB", ""),
  129.         new Locale("EN", "CA", ""),
  130.         new Locale("FR", "FR", ""),
  131.         new Locale("FR", "CA", ""),
  132.         new Locale("DE", "DE", ""),
  133.         new Locale("IT", "IT", ""),
  134.     //new Locale("JA", "JP", ""),
  135.     };
  136. }
  137.